package com.bcxj.servicemessage.consumer;

import com.bcxj.servicemessage.scoketserver.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class KafkaConsumer {

    @Autowired
    private WebSocketServer webSocketServer;

    /**
     * 消费交通区域统计数据
     */
    @KafkaListener(topics = "${kafka.topic.traffic-area-stats}")
    public void consumeAreaStats(String message) {
        log.info("接收到区域交通统计数据: {}", message);
        webSocketServer.sendToAllClient("traffic-area-stats", message);
    }

    /**
     * 消费交通预警数据
     */
    @KafkaListener(topics = "${kafka.topic.traffic-alerts}")
    public void consumeTrafficAlerts(String message) {
        log.info("接收到交通预警数据: {}", message);
        webSocketServer.sendToAllClient("traffic-alerts", message);
    }

    /**
     * 消费城市交通概览数据
     */
    @KafkaListener(topics = "${kafka.topic.traffic-city-overview}")
    public void consumeCityOverview(String message) {
        log.info("接收到城市交通概览数据: {}", message);
        webSocketServer.sendToAllClient("traffic-city-overview", message);
    }
} 